/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.aeso.betabit.util;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Tomcat;

/**
 *
 * @author Edson
 */
public class REST {
    
    private static final String HOSTNAME = "localhost";
    private static final String APP_BASE = "../res";
    private static final int PORT = 8083;
    private static final String BASEDIR = "target";
    
    public static void startup() {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Host host = new StandardHost();
                    host.setName(REST.HOSTNAME);
                    host.setAppBase(REST.APP_BASE);

                    Tomcat tomcat = new Tomcat();
                    tomcat.setPort(REST.PORT);
                    tomcat.setBaseDir(REST.BASEDIR);

                    Engine engine = tomcat.getEngine();
                    engine.addChild(host);

                    tomcat.addWebapp(host, "/", REST.APP_BASE);
                    tomcat.start();
                    System.in.read();
                } catch (IOException | LifecycleException ex) {
                    Logger.getLogger(REST.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        t.start();
    }
}